
#include "binary_tree.h"
#include "stdio.h"

int main(void)
{
    /*第一步*/
    BSTREE *bstree = bstree_create();

    bstree_insert(bstree, 50);
    bstree_insert(bstree, 70);
    bstree_insert(bstree, 20);
    bstree_insert(bstree, 60);
    bstree_insert(bstree, 40);
    bstree_insert(bstree, 30);
    bstree_insert(bstree, 10);
    bstree_insert(bstree, 90);
    bstree_insert(bstree, 80);

    /*第二步*/
    bstree_print(bstree);

    /*第三步*/
    bstree_intravel(bstree);

    bstree_pretravel(bstree);

    bstree_postravel(bstree);

    /*第四步*/
    printf("node num = %d, tree height =%d\n", bstree_size(bstree), bstree_height(bstree));

    /*第五步*/
    bstree_erase(bstree,60);
    bstree_print(bstree);
    printf("-----------------------------------------------------------------------------\n");    
    /*第六步*/
    
    bstree_insert(bstree, 50);
    bstree_insert(bstree, 50);
    bstree_print(bstree);
    printf("-----------------------------------------------------------------------------\n");    

    bstree_remove(bstree,50);
    bstree_print(bstree);
    printf("-----------------------------------------------------------------------------\n");    
    
    /*第七步*/
    
    bstree_insert(bstree, 40);
    bstree_insert(bstree, 40);
    bstree_print(bstree);
    printf("-----------------------------------------------------------------------------\n");    
    
    bstree_update(bstree, 40, 85);
    bstree_print(bstree);
    printf("-----------------------------------------------------------------------------\n");    

    /*第八步*/    
	printf ("%d, %d\n", bstree_exist (bstree, 40),
		bstree_exist (bstree, 85));

	bstree_destroy (bstree);


    return 0;

}
